<%@page import="model.StudentDAO"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>


<script type="text/javascript">
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
	XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
	XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function getData(obj) {
	
	if(XMLHttpRequestObject) {		
		var url = "FindData?mssv=" + obj;
		
		XMLHttpRequestObject.open("GET", url, true);
		XMLHttpRequestObject.onreadystatechange = function(){				
			if (XMLHttpRequestObject.readyState == 4 &&
					XMLHttpRequestObject.status == 200) {
					var text = XMLHttpRequestObject.responseText;
					
					var p0 = 0;
					var p1 = text.indexOf("-", 1);
					var p2 = text.indexOf("-", p1 + 1);
					var pf = text.length;
					
					var c1 = text.substring(0, p1);
					var c2 = text.substring(p1 + 1, p2);
					var c3 = text.substring(p2 + 1, pf);
					
					var o1 = document.getElementById("c1");
					var o2 = document.getElementById("c2");
					var o3 = document.getElementById("c3");
					
					o1.innerHTML = c1;					
					o2.innerHTML = c2;					
					o3.innerHTML = c3;					
				}
		}
		XMLHttpRequestObject.send(null);
	}
}


</script>


</head>
<body>
<h3>Find Student Information</h3>

<%
List<String> ms = new StudentDAO().getAllMSSV();
%>

<form action="">
<select>
<% for (String string : ms) {%>
<option onclick="getData(<%= string %>)" value="<%= string %>" ><%= string %> </option>
<%} %>
</select>
</form>
<br /><br /><br />
<pre style="font-size: xx-large;">
		MSSV:    <span id="c1"></span>
		Name:    <span id="c2"></span>
		AGrade:  <span id="c3"></span>
</pre>
</body>
</html>